home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Crossword / Source / LeapfrogSquare.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  90 lines

  1. /*
  2.  
  3. File LeapfrogSquare.m
  4.  
  5. These are the squares used for leapfrog search.  When backjumping past a square, the square remembers its current value and tries that value first the next time through.
  6.  
  7. */
  8.  
  9. #import <appkit/appkit.h>
  10.  
  11. #import "Leapfrog.h"
  12. #import "Crossword.h"
  13. #import "Puzzle.h"
  14.  
  15.  
  16. /* ————————————————————————————————————————————————————————————————————————————  */
  17.  
  18.  
  19. #define position(i)        ((wordPosition *) [words  elementAt: i])
  20. #define forword(c)        ((c) == WILDCARD ? (c):(c) + 'a')
  21. #define forcell(c)        ((c) == WILDCARD ? EMPTY:(c) + 'A')
  22.  
  23.  
  24. /* ————————————————————————————————————————————————————————————————————————————  */
  25.  
  26.  
  27. @implementation LeapfrogSquare
  28.  
  29.  
  30. - initPuzzle: (id) thePuzzle  cell: (id) theCell
  31. {
  32.     [super  initPuzzle: thePuzzle  cell: theCell];
  33.     last = WILDCARD;
  34.     
  35.     return self;
  36. }
  37.  
  38.  
  39. - show
  40. {
  41.     char    symbol;
  42.     
  43.     symbol = (last == WILDCARD) ? letter:last;
  44.     [[puzzle  getCrossword]  putLetter: forcell(symbol)  inSquare: cell];
  45.     DPSFlush();
  46.     
  47.     return self;
  48. }
  49.  
  50.  
  51. - (char) chooseLetter
  52. {
  53.     char    best;
  54.     
  55.     if ((last != WILDCARD) && (count[last] != 0))
  56.     {
  57.         [self  clearStatus: JUMPED];
  58.         best = last;
  59.         last = WILDCARD;
  60.     }
  61.     
  62.     else
  63.     {
  64.         last = letter;
  65.         best = [super  chooseLetter];
  66.         if (!injump) last = WILDCARD;
  67.     }
  68.     
  69.     return best;
  70. }
  71.  
  72.  
  73. /* ————————————————————————————————————————————————————————————————————————————  */
  74.  
  75.  
  76. - update
  77. {
  78.     [super  update];
  79.     
  80.     if ((last != WILDCARD) && (count[last] == 0))
  81.     {
  82.         last = WILDCARD;
  83.         [self  show];
  84.     }
  85.     
  86.     return self;
  87. }
  88.  
  89.  
  90. @end